<!-- 搜索表单 -->
<template>
<el-card shadow="never" >
  <el-form
    label-width="77px"
    class="ele-form-search"
    @keyup.enter.native="search"
    @submit.native.prevent
  >
    <el-row :gutter="24">
      <el-col :lg="7" :md="24">
        <el-form-item label="秒杀时间:">
          <el-date-picker v-model="where.date"  type="datetimerange"
                range-separator="至" start-placeholder="秒杀开始时间" end-placeholder="秒杀结束时间"  :default-time="['00:00:00', '23:00:00']">
            </el-date-picker>
        </el-form-item>
      </el-col>
      <el-col :lg="4" :md="24">
        <el-form-item label="状态:">
          <el-select v-model="where.status" clearable placeholder="请输入状态">
            <el-option v-for="(item, index) in statusEnums" :key="index" :label="item.Value" :value="item.Key" />
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :lg="6" :md="24">
        <div class="ele-form-actions">
          <el-button
            type="primary"
            icon="el-icon-search"
            class="ele-btn-icon"
            @click="search"
          >
            查询
          </el-button>
          <el-button @click="reset">重置</el-button>
        </div>
      </el-col>
    </el-row>
  </el-form>
</el-card>
</template>

<script>
  const DEFAULT_WHERE = {
    date: '',   //关键字
    status: '' //状态
  };
  import { QuerySpikeStatusEnum } from '@/api/enummanger';
  export default {
    name: 'SpikeSearch',
    data() {
      return {
        //系统状态
        statusEnums: [],
        // 表单数据
        where: { ...DEFAULT_WHERE },
      };
    },
    //初始化数据
    created(){
      this.queryStatusEnums();
    },

    methods: {

      /* 搜索 */
      search() {

      let params = {
          pageindex: 1,
          conditions: [],
          orderBys: [{ sort: "createDate", order: 1, }],
        };

        //采购日期
        if(this.where.date){
          params.conditions.push({
            key:"spikeSDate",
            operator: 3,
            value: this.where.date[0],
          });

          params.conditions.push({
            key:"spikeEDate",
            operator: 5,
            value: this.where.date[1] ,
          });

          // params.conditions.keyword =  this.where.keyword;
          // params.conditions.keyword =  this.where.keyword;
        }

        //状态查询
        if(this.where.status ===1 || this.where.status ===5|| this.where.status ===100){
          params.conditions.push({
            key:"status",
            operator: 0,
            value: this.where.status,
          });
        }

        this.$emit('search', params);
      },
      /*  重置 */
      reset() {
        this.where = { ...DEFAULT_WHERE };
        this.search();
      },

      /* 系统状态 */
      async queryStatusEnums(){
        let sysEnums = await QuerySpikeStatusEnum();
        sysEnums.map(e=>{
          this.statusEnums.push({Key:e.Key,Value:e.Value});
        });
      },
    }
  };
</script>
